BEP-5: Integral to differential
Abstract: This BEP proposes a function to find the linear differential system
associated to a given impulse response (e.g. PSPs, PSCs, STDP rules...).
Experimental module: experimental/integrodiff

Example: g(t)=t*exp(-t/tau)
should be converted to:
dg/dt=(x-g)/tau
dx/dt=-x/tau
with appropriate scaling, and the initial condition x=1,g=0 at time t=0.

Idea: use the automatic differentiation to calculate d^ng/dt^n and calculate the rank
of a set of vectors g^{(n)}(t_i) to find the dimension. Then use e.g. least square
minimization to find the matrix.
Issue: this does not work if there are free variables (e.g. tau).

Implementation proposal:
------------------------
eqs=equations("g(t)=t*exp(-t/tau)") # returns Equations or string object
# I couldn't find a proper name for the function!

The differential system contains variables g and g_in and is such that the solution
with initial condition g_in=1 and x=0 for all other variables is such that g(t) matches
the given expression.
How to do it:
* A duration T is passed (typically a few times tau)
* re matching to extract g, t (time variable) and the RHS expression
* conversion to a function of t
* nth-derivatives of g are calculated with automatic differentiation
* N points are randomly drawn in [0,T] and N vectors are calculated, each vector
holds the value of g^{(i)}(t_j).
* The rank is calculated as follows: calculate the best LSQ approximation of g{(n)} as
a function of g^i (i<n). When the residual error does not change significantly from n to n+1, 
then the rank is n.
* A matrix A has been found such that dX/dt=AX, where x_0=g and x_i=g^{(i)}. In fact
the matrix is such that for i<n-1, a_ii+1=1 and a_ij=0 otherwise. The last row comes from
the LSQ calculation.
* The initial condition is found by calculating the derivatives at time 0.
* Now a change of variables must be done so that variable x_0 is unchanged and the solution
matches the initial condition problem, i.e., such that Y0=PX0, with X0 the initial
condition in the original system and Y0 in the new system. It can be easily seen that the
change of variable is such that the last column of P^{-1} is X0, and the first row is
(1,0,...), implying in particular that g(0)=0 (except for 1-dimensional systems, e.g.,
g(t)=exp(-t/tau)). Any such (invertible) P will work.
* If g(0)!=0, then the initial condition should be x_0=g(0) and all other variables are null
at time 0. It follows that the first column of P^{-1} is X0 and the first row is
(g(0),0,...).
* A is replaced by PAP^{-1}.
